@extends('admin/index')
@section('name')
    <h1><span class="label label-default"> 用户管理  </span></h1>
    <hr>

    <table class="table table-bordered  table-hover" id="tent">
        <tr>
            <th>ID</th>
            <th>手机号</th>
            <th>昵称</th>
            <th>头像</th>
            <th>注册时间</th>
            <th>会员</th>
            <th>大V</th>
            <th>操作</th>
        </tr>
        @foreach($result as $list)
            <tr>
                <th>{{$list->id}}</th>
                <th>{{$list->u_tel}}</th>
                <th>{{$list->u_name}}</th>
                <th><img src="{{$list->u_img}}" width="30px"></th>
                <th>{{$list->u_regtime}}</th>
                <th>
                    @if(($list->u_member) === 0)
                        NO
                    @elseif(($list->u_member) === 1)
                        YES
                    @endif
                </th>
                <th>
                    @if(($list->u_v) === 0)
                        NO
                    @elseif(($list->u_v) === 1)
                        YES
                    @endif
                </th>
                <th>
                    <a href="/main/update/{{$list->id}}" class="btn btn-info">修改</a>
                    <button class="btn btn-danger" id="but1" onclick="del({{$list->id}})">删除</button>
                </th>
            </tr>
        @endforeach
    </table>
    {{--<script src="http://cdn.bootcss.com/jquery/1.11.2/jquery.min.js"></script>--}}
    {{--<script type="text/javascript" src="{{url('js/admin/jquery-1.8.3.min.js')}}"></script>--}}
    {{$result->links()}}
    <script>
        function del($id) {
            var id = $id;

            $.ajax({
                type: 'get',
                url: "{{url('/main/del')}}/" + id,
                data: id, //发送请求数据
                success: function (data) {
                    console.log(data);
                    if (data == 1) {
                        $("table#tent tr").click(function () {
                            $(this).remove();
                        });
                        window.location.href='{{url('/main')}}';
                    } else {
                        alert('删除失败');
                    }
                },
                error:function () {
                    alert('ajax请求失败');
                }
            });
        }
    </script>

    @if(!empty(session('error')))
        <script>
            alert('{{session('error')}}')
        </script>
    @endif

@endsection
